package com.facemox.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.facemox.bean.User;

public interface UserMapper {
    
 // 根据username查询用户
    @Select("select * from face_user where username=#{username}")
    @Results({
        @Result(column = "user_id",property = "userId"),
        @Result(column = "username",property = "username"),
        @Result(column = "password",property = "password"),
        @Result(column = "create_time",property = "createTime")
    })
    User getUserByUsername(String username);
	
	// 插入一条数据
    @Insert("INSERT INTO face_user(name,phone,create_time,age) values(#{name},#{phone},#{createTime},#{age})")
    // 1、获取数据库自增ID，keyProperty：java对象的属性，keyColumn：数据库字段名称
    @Options(useGeneratedKeys=true,keyProperty="id",keyColumn="id")
    int insert(User user);
    
    // 查找全部
    @Select("select * from face_user")
    @Results({
    	@Result(column = "create_time",property = "createTime")
    })
    List<User> getAll();
    
    // 根据id查询
    @Select("select * from face_user where id=#{id}")
    @Results({
    	@Result(column = "create_time",property = "createTime")
    })
    User findById(String id);
    
    // 根据id更新
    @Update("update face_user set name=#{name} where id=#{id}")
    int update(User user);
    
    // 根据id删除用户
    @Delete("delete from face_user where id=#{id}")
    int delete(String id);
}
